package jzoffer;

/**
 * 每个空格替换成%2
 */
public class ReplaceSpace {
    public static String replaceSpace(String s) {
        if (s == null) {
            return "";
        }
        final char SPACE = ' ';
        int length = s.length();
        char[] result = new char[length * 3];
        if ("".equals(s)) {
            return "";
        }
        int size = 0;
        for (int i = 0; i < length; i++) {
            char c = s.charAt(i);
            if (c == SPACE) {
                result[size++] = '%';
                result[size++] = '2';
                result[size++] = '0';
            }else {
                result[size++]=c;
            }
        }
        String resultStr=new String(result,0,size);
        return resultStr;
    }
}
